/**
 * 
 */
package com.demo2do.fms.admin.entity.search.data;

import java.math.BigDecimal;
import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 * @author Chang Liu
 *
 */
public class RoadBridgeFeeSearch implements QueryBuilder {
    
    private Long organizationId;
    
    private BigDecimal minTon;
    
    private BigDecimal maxTon;
    
    private QueryFilter filter;
    
    private QueryOrder order;

    /**
     * 
     * the default constructor
     */
    public RoadBridgeFeeSearch() {
        order = new QueryOrder().add("organization", "ASC")
                                .add("emp", "ASC")
                                .add("ton", "ASC");
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if(filter == null || refresh){
            
            filter = new QueryFilter().addEquals("organization.id", organizationId)
                                      .addGreaterThanEqual("ton", minTon)
                                      .addLessThanEqual("ton", maxTon);
        }
        return filter;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return order;
    }
    
    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM RoadBridgeFee WHERE disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }

    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }

    /**
     * @return the organizationId
     */
    public Long getOrganizationId() {
        return organizationId;
    }
    
    /**
     * @return the minTon
     */
    public BigDecimal getMinTon() {
        return minTon;
    }

    /**
     * @return the maxTon
     */
    public BigDecimal getMaxTon() {
        return maxTon;
    }

    /**
     * @param organizationId the organizationId to set
     */
    public void setOrganizationId(Long organizationId) {
        this.organizationId = organizationId;
    }

    /**
     * @param minTon the minTon to set
     */
    public void setMinTon(BigDecimal minTon) {
        this.minTon = minTon;
    }

    /**
     * @param maxTon the maxTon to set
     */
    public void setMaxTon(BigDecimal maxTon) {
        this.maxTon = maxTon;
    }
    
}
